using System;
using System.Collections.Generic;
using System.Text;
using OpenComposite.Base.Designer;
using System.Drawing;
using OpenComposite.EII.Designer.SCA;

namespace OpenComposite.EII.Designer.Generic
{
	public class ExternalSymbol : Symbol, IConnector, IConnectorFactory
	{
		#region Initialization
		public ExternalSymbol()
		{
			init();
		}
		private void init()
		{
			this.BeginUpdate();

			//this.Name = "externalSymbol" + GetCount(typeof(ExternalSymbol));
			this.Text = "Extern";
			this.TextAlign = ContentAlignment.MiddleCenter;

			this.Size = new Size(70, 40);
			this.MaximumSize = new Size(70, 40);
			this.MinimumSize = new Size(70, 40);

			this.Border = BorderType.Ellipse;
			this.BorderColor = Color.LightBlue;
			this.BorderWidth = 5;
			this.BackBrushMode = BackgroundBrushMode.LinearGradient;
			this.BackLinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal;
			this.BackColor = Color.AliceBlue;
			this.BackColor2 = Color.LightBlue;

			this.NameTextBox.BorderVisibilityStyle = BorderVisibilityStyle.MouseOverAndFocus;
			this.NameTextBox.AutoSize = false;
			this.NameTextBox.BackColor = Color.Transparent;
			this.NameTextBox.Top = (int)( this.ClientRectangle.Height / 2 ) - (int)( this.NameTextBox.Height / 2 );

			this.EndUpdate();
		}
		#endregion

		#region Public Members

		#region Override

		#region Properties
		public override bool CanFocused
		{
			get
			{
				return true;
			}
		}
		public override bool CanMove
		{
			get
			{
				return true;
			}
		}
		public override bool CanResize
		{
			get
			{
				return false;
			}
		}
		public override bool CanSelect
		{
			get
			{
				return true;
			}
		}
		public override bool IsContainer
		{
			get
			{
				return false;
			}
		}
		public override bool NoClip
		{
			get
			{
				return false;
			}
		}
		#endregion

		#region Drag & Drop
		public override object GetDragObject(Point location, System.Windows.Forms.MouseButtons button)
		{
			return this;
		}
		public override bool IsDropAllowed(object obj, Point location, System.Windows.Forms.MouseButtons button)
		{
			return ( ( obj is InterfaceSymbol || obj is ReferenceSymbol || obj is ITStructure.ITObjectSymbol ||
					   obj is BusinessServices.BusinessServiceSymbol ) &&
					obj != this && button == System.Windows.Forms.MouseButtons.Right );
		}
		public override void DropObject(object obj, Point location, System.Windows.Forms.MouseButtons button)
		{
			if ( this.IsDropAllowed(obj, location, button) ) {
				if ( obj is InterfaceSymbol )
					this.DesignerViewControl.AddRoute(this, (DesignerControl)obj);
				else
					this.DesignerViewControl.AddRoute((DesignerControl)obj, this);
			}
		}
		#endregion

		#endregion

		#region IConnector Members

		public override Point GetRouteEnd(RouteDockDirection dock, Route route)
		{
			Rectangle b = this.GetPaintBounds();
			return new Point(b.X + ( b.Width / 2 ), b.Y + ( b.Height / 2 ) - 10);
		}
		public override Point GetRouteStart(RouteDockDirection dock, Route route)
		{
			Rectangle b = this.GetPaintBounds();
			return new Point(b.X + ( b.Width / 2 ), b.Y + ( b.Height / 2 ) + 10);
		}

		#endregion

		#region IConnectorFactory Members

		public override bool CreateRouteEnd(DesignerControl controlStart, out IConnector connector,
			out System.Drawing.Drawing2D.LineCap cap, out System.Drawing.Drawing2D.CustomLineCap customcap,
			out RouteDockDirection dockStart, out RouteDockDirection dockEnd,
			out bool useEndConnectorAsRouteEnd)
		{
			connector = this;
			cap = System.Drawing.Drawing2D.LineCap.Custom;
			customcap = new System.Drawing.Drawing2D.AdjustableArrowCap(10.0f, 5.0f, false);
			dockStart = RouteDockDirection.Undefined;
			dockEnd = RouteDockDirection.Top;
			useEndConnectorAsRouteEnd = false;
			return true;
		}
		public override bool CreateRouteStart(DesignerControl controlEnd, out IConnector connector,
			out System.Drawing.Drawing2D.LineCap cap, out System.Drawing.Drawing2D.CustomLineCap customcap,
			out RouteDockDirection dockStart, out RouteDockDirection dockEnd,
			out bool useStartConnectorAsRouteStart)
		{
			bool ok = base.CreateRouteStart(controlEnd, out connector, out cap, out customcap, out dockStart,
				out dockEnd, out useStartConnectorAsRouteStart);
			dockStart = RouteDockDirection.Bottom;
			return ok;
		}

		#endregion
		#endregion

	}
}
